<script setup>
import { ref } from 'vue'
// 动画 animate.css
import "animate.css"
// 引入瀑布流布局插件
import { LazyImg,Waterfall } from 'vue-waterfall-plugin-next'
import { getProductListByLocationService } from '@/api/product.js'
import { useUserStore } from '@/stores/index'
import { Star } from '@element-plus/icons-vue'
const userStore = useUserStore()

// -------------------------获取商品列表-------------------------------
const getProductListByLocation = async () =>{
  const res = await getProductListByLocationService(userStore.province,userStore.city)
  productList.value = res.data.data
}
getProductListByLocation()

// 商品分类数据
const productList = ref([])
const breakpoints = ref({
  1600: {
    // when wrapper width < 1200
    rowPerView: 5,
  }
})
</script>
<template>
  
  <div class="recommend-container animate__animated animate__zoomIn ">
    <el-empty v-if="productList[0] == null" :image-size="200" />
    <!-- 瀑布流布局 -->
    <Waterfall v-if="productList.length" :list="productList" :gutter="18" :imgSelector="'coverImage'" :crossOrigin="false"
    :breakpoints :animationEffect="'animate__zoomIn'" >
      <template #item="{ item,url }">
        <div class="waterfull-card">
          <!-- 封面 -->
          <LazyImg :url="url" style="border-radius: 15px;width: 220px;" />
          <div class="footer">
            <!-- 标题 -->
            <a class="title"><span>{{ item.title }}</span></a>
            <!-- 价格和发货方式 -->
            <div class="price">
              <span style="color: red; font-weight: 600; font-size: 15px;">￥{{item.price}}</span>
              <span style="font-size: 12px;color: #9e9e9e;">{{ item.postType === 0 ? '邮寄' : '自提' }}</span>
            </div>
            <!-- 头像和想要人数 -->
            <div class="avatar-Like">
              <div class="avatar">
                <img class="avatar-img"
                  :src="item.avatar || 'https://cc-alchemy.oss-cn-beijing.aliyuncs.com/male.png'"
                  style="width: 25px; border-radius: 50%; outline: none;">
                <span style="margin-left: 5px; color: #5c5c5c; font-size: 12px;">{{item.nickName}}</span>
              </div>
              <div class="like">
                <span>
                  <el-icon style="font-size: 14px; color: #5c5c5c; ">
                    <Star />
                  </el-icon>
                </span>
                <span style="font-size: 12px; color: #5c5c5c;">100+</span>
              </div>
            </div>
          </div>

        </div>
      </template>
    </Waterfall>
  </div>
</template>
<style lang="less" scoped>
// you 
.animate__animated {
  animation-fill-mode: both;
  animation-duration: 0.5s;
}

// y
.waterfull-card {
  transition: all .4s;
  &:hover{
    transform: translateY(-10px);
  }

  .footer {
    padding: 10px;

    .title {
      display: block;
      margin-bottom: 5px;
      padding-left: 5px;
    }

    .price {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 5px;
    }

    .avatar-Like {
      display: flex;
      justify-content: space-between;
      align-items: center;

      .avatar {
        display: flex;
        align-items: center;
      }

      .like {
        display: flex;
        align-items: center;
        font-style: 12px;
      }
    }
  }
}
</style>